import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'

import axios from 'axios'

import router from './router'
import store from './store/index'

import 'normalize.css'

Vue.use(ElementUI)

Vue.prototype.$axios = axios;

router.beforeEach((to, from, next) => {
	if (to.matched.some(record => record.meta.requiresAuth)) {
		var isLogin = store.state.user.apiUserId > 0;
		//var isLogin = true;
		if (!isLogin) {
			next({
				path: '/login',
				query: {redirect: to.fullPath}
			});
		}else {
			next();
		}
	}else {
		next();
	}
})


new Vue({
  el: '#app',
  data: {
  	eventHub: new Vue()
  },
  store,
  router,
  render: h => h(App)
})
